package com.example.homeworkmanagement.controller;


import com.example.homeworkmanagement.pojo.Attachments;
import com.example.homeworkmanagement.service.AttachmentsService;
import com.example.homeworkmanagement.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 拒绝加班
 * @since 2025-05-25
 */
@RestController
@RequestMapping("/attachments")
@Api(tags="附件管理",description="提供管理API接口")
@CrossOrigin
public class AttachmentsController {
    @Autowired
    private AttachmentsService attachmentsService;

    /**
     * 删除附件（根据附件ID）
     */
    @DeleteMapping("/deleteAttachment")
    @ApiOperation(value = "根据附件ID删除附件")
    @ApiImplicitParam(name = "attachmentId", value = "附件ID", required = true, dataType = "Integer")
    public ResultVO<?> deleteAttachmentByAttachmentId(Integer attachmentId) {
        return attachmentsService.deleteAttachment(attachmentId);
    }

    /**
     * 下载附件（根据附件ID）
     */
    @PutMapping("/downloadAttachmentByAttachmentId")
    @ApiOperation(value = "根据附件ID下载附件")
    @ApiImplicitParam(name = "attachmentId", value = "附件ID", required = true, dataType = "Integer")
    public ResultVO<?> downloadAttachmentByAttachmentId(Integer attachmentId) {
        return attachmentsService.downloadAttachmentByAttachmentId(attachmentId);
    }
}
